
// #include <stdio.h>

#define N_ELEM 5120000

int main (int argc)
{
 int i;
  int n = N_ELEM;
  float pi = 0.0f;
  float  sum = 0.0f;
   float h;
  // This could be run in the device 
  sum = 0.0f;   // Initial value to a global var
 
#pragma data kernels name("compute_pi") copyout(pi) copyin(n) copy(sum) create(h)
 {
  h = 1.0 / (float) n;   // local var to the device
  #pragma acc loop reduction(+: sum) pcopyin(h)
  for (i = 0; i <= n; i ++)
    {
      float x = h * ((float) i - 0.5);
      sum += 4.0 / (1.0 + x * x);
    }
 }

 pi = h * sum;

 printf ("Pi %f \n", pi);


}
